package com.yanqu.road.server.cmd.activity.huashigang;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eSceneType;
import com.yanqu.road.entity.scene.ScenePlayerInfo;
import com.yanqu.road.logic.pb.ScenePb;
import com.yanqu.road.pb.huashigang.HuaShiGangProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.huashigang.HuaShiGangMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @Author wpj
 * @Date 2020/10/14
 */
@Cmd(code = GameProtocol.S_HUA_SHI_GANG_GET_MONSTER_DATA, desc = "获取怪物数据")
public class GetMonsterDataCmd extends AbstractCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
//        ret = HuaShiGangMgr.getActivityInfoRet(player);
//        if (ret != 0) {
//            return;
//        }
        ActivityInfo activityInfo = HuaShiGangMgr.getActivityInfo();
        if (!ActivityMgr.activityInTime(activityInfo)) {
            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }

        HuaShiGangProto.CrossGetHuaShiGangMonsterDataReqMsg.Builder builder = HuaShiGangProto.CrossGetHuaShiGangMonsterDataReqMsg.newBuilder();
        builder.setActivityId(activityInfo.getActivityId());
        builder.setScene(ScenePb.parseSceneMsg(
                activityInfo.getActivityId(),
                eSceneType.HuaShiGangMonster.getValue(),
                "",
                new ScenePlayerInfo(GameServer.getInstance().getServerId(), player.getUserId(), player.getUserInfo().getNickName(), player.getUserInfo().getDecoration()),
                System.currentTimeMillis()
        ));
        player.sendPacket(CrossProtocol.C2_HUA_SHI_GANG_GET_MONSTER_DATA, builder);

    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            HuaShiGangProto.GetHuaShiGangMonsterDataRespMsg.Builder builder = HuaShiGangProto.GetHuaShiGangMonsterDataRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_HUA_SHI_GANG_GET_MONSTER_DATA, builder);
        }
    }
}
